package com.fanshe.demo04;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Demo01 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        //mothod01();
        Class aClass = Class.forName("com.fanshe.demo04.Student");
        Constructor constructor = aClass.getConstructor();
        constructor.setAccessible(true);
        Object o = constructor.newInstance();
        Field money = aClass.getDeclaredField("money");
        money.setAccessible(true);
        money.set(o, 5000000);
        Object o1 = money.get(o);
        System.out.println(o1);
        Field gender = aClass.getDeclaredField("gender");
        System.out.println(gender);

    }

    private static void mothod01() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchFieldException {
        Class aClass = Class.forName("com.fanshe.demo04.Student");
        Constructor ctr = aClass.getDeclaredConstructor();
        ctr.setAccessible(true);
        Object o = ctr.newInstance();
        Field money = aClass.getDeclaredField("money");
        money.setAccessible(true);
        money.set(o, 5000000);
        Object o1 = money.get(o);
        System.out.println(o1);
        Field gender = aClass.getDeclaredField("gender");
        System.out.println(gender);
    }
}
